<?php
namespace App\Http\Controllers;

use App\Models\Food;
use App\Models\Foodmenu;
use Illuminate\Support\Facades\Schema;

class FoodController extends WxBaseController {
    protected $except=['index','show','menu'];
    public function index($order='recommended'){
        $foods = Food::orderBy($order,'desc')->get();
        editImageUrl($foods);
        $menus = Foodmenu::get();
        return $this->apiReturn(true,'success',['food'=>$foods,'menus'=>$menus]);
    }

    public function menu(){
        $menus = Foodmenu::get(['id','text']);
        return response()->json($menus);
    }
    public function show($id){
        $food = Food::where('id',$id);
        //更新浏览量
        if(Schema::hasColumn('foods', 'watch')){
            $food->increment('watch');
        };
        $arr = $food->get();
        editImageUrl($arr);
        return $this->apiReturn(true,'success',$arr);
    }
}